package com.turtle.security.organizates.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turtle.security.organizates.constant.SysMenuConstant;
import com.turtle.security.organizates.dto.SysMenuDTO;
import com.turtle.security.organizates.entity.SysMenu;
import com.turtle.security.organizates.mapper.SysMenuMapper;
import com.turtle.security.organizates.service.ISysMenuAddService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 添加目录菜单
 *
 * @author turtle
 * date: 2020-06-01
 */
@Service
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class SysCatalogueMenuAddServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuAddService {
    private final SysMenuMapper sysMenuMapper;

    /**
     * 获取菜单类型
     *
     * @return menuType
     */
    @Override
    public String getMenuType() {
        return SysMenuConstant.CATALOGUE_MENU_TYPE;
    }

    /**
     * 添加目录菜单
     *
     * @param sysMenu 菜单信息
     */
    @Override
    public void menuAdd(SysMenuDTO sysMenu) {
        SysMenu menu = SysMenu.builder()
            .menuName(sysMenu.getMenuName())
            .menuType(SysMenuConstant.CATALOGUE_MENU_TYPE)
            .menuCategory(sysMenu.getMenuCategory())
            .status(sysMenu.getStatus())
            .visible(sysMenu.getVisible())
            .parentId(sysMenu.getParentId())
            .remark(sysMenu.getRemark())
            .orderNum(sysMenu.getOrderNum())
            .path(sysMenu.getPath())
            .icon(sysMenu.getIcon())
            .build();
        sysMenuMapper.insert(menu);

    }

    /**
     * 更新目录菜单
     *
     * @param sysMenu 菜单信息
     */
    @Override
    public void menuUpdate(SysMenuDTO sysMenu) {
        SysMenu menu = SysMenu.builder()
            .menuId(sysMenu.getMenuId())
            .menuName(sysMenu.getMenuName())
            .menuType(SysMenuConstant.CATALOGUE_MENU_TYPE)
            .menuCategory(sysMenu.getMenuCategory())
            .status(sysMenu.getStatus())
            .visible(sysMenu.getVisible())
            .parentId(sysMenu.getParentId())
            .remark(sysMenu.getRemark())
            .orderNum(sysMenu.getOrderNum())
            .path(sysMenu.getPath())
            .icon(sysMenu.getIcon())
            .build();
        sysMenuMapper.updateById(menu);

    }
}
